package com.ccp.dev.system.consts;

import com.ccp.dev.core.util.AppUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassDescribe:文件管理常量类
 * Author :zhaowanjing
 * Date: 2018-05-24
 */
public class FileManagementContants {

    //文件类型 1文件夹 2文件
    public static final int FILE_TYPE_FOLDER = 1;

    public static final int FILE_TYPE_FILE = 2;

    //父节点类型 1物理树目录节点 2逻辑归类树目录节点
    public static final int PARENT_TYPE_TREE = 1;

    public static final int PARENT_TYPE_LOGICTREE = 2;

    //文件密级 1公开资料 2内部资料 3秘密 4机密 5绝密
    public static final int FILE_SECRET_PUBLIC = 1;

    public static final int FILE_SECRET_INTERNAL = 2;

    public static final int FILE_SECRET_SECRET = 3;

    public static final int FILE_SECRET_MIDDLE_SECRET = 4;

    public static final int FILE_SECRET_TOP_SECRET = 5;

    //删除文件返回值信息 noFile无此文件 success删除成功 error删除失败 otherUserFile包含其他用户文件
    public static final String DELETE_FILE_NO_FILE = "noFile";

    public static final String DELETE_FILE_SUCCESS = "success";

    public static final String DELETE_FILE_ERROR = "error";

    public static final String DELETE_FILE_OTHER_USER_FILE = "otherUserFile";

    public static final String DELETE_FILE_DELETEIDS = "deleteIds";

    public static final String DELETE_FILE_DELETEPATHS = "deletePaths";

    public static final String DELETE_FILE_CANTDELETE = "-1";


    //重命名文件返回值信息 noFile无此文件 success重命名成功 nameRepeat名称重复 error重命名失败

    public static final String FILE_REMANE_NO_FILE = "noFile";

    public static final String FILE_REMANE_SUCCESS = "success";

    public static final String FILE_REMANE_ERROR = "error";

    public static final String FILE_REMANE_NAMEREPEAT = "nameRepeat";

    public static final String FILE_REMANE_NOREPEAT = "noRepeat";

    //此文件是否已经映射过此文件夹
    public static final boolean FILE_MAPPING_TRUE = true;

    public static final boolean FILE_MAPPING_FALSE = false;

    //文件密级的数据字典类型
    public static final String FILE_SECRET_TYPE = "5";

    //系统属性 上传的文件类型限制
    public static final String FILE_UPLOAD_TYPE = "35";

    //根节点的父节点ID
    public static final String ROOT_PARENT_ID = "-1";

    //页面传过来的父节点
    public static final String JSP_PARENT_ID = "0";

    //用户密级  1非密 2内部 3一般 4重要 5核心
    public static final Map<Integer, String> userSecretMap = new HashMap();

    static {
        userSecretMap.put(1, "USER_SECRET_PUBLIC");
        userSecretMap.put(2, "USER_SECRET_INSIDE");
        userSecretMap.put(3, "USER_SECRET_GENERAL");
        userSecretMap.put(4, "USER_SECRET_IMPORTANT");
        userSecretMap.put(5, "USER_SECRET_TOP_SECRET");
    }

    //操作类型  1上传 2下载 3删除 4重命名

    public static final int FILE_OPERATOR_UPLOAD = 1;

    public static final int FILE_OPERATOR_DOWNLOAD = 2;

    public static final int FILE_OPERATOR_DELETE = 3;

    public static final int FILE_OPERATOR_RENAME = 4;

    //压缩文件后缀
    public static final String FILE_ZIP_FORMAT = ".zip";

    //权限控制的类型 1：操作按钮  2：目录节点
    public static final int PERMISSION_BUTTON = 1;

    public static final int PERMISSION_NODE = 2;

    //操作按钮的nodeId默认入-1
    public static final String BUTTON_NODEID = "-1";

    /**
     * 通过用户密级获取文件密级权限信息
     *
     * @param userSecret 用户密级
     * @return 文件密级数组
     */
    public static int[] getFileSecretByUserSecret(int userSecret) {
        String userSecretStr = userSecretMap.get(userSecret);
        List<String> fileSecretLevels = (List<String>) AppUtil.getBean(userSecretStr);
        int[] arr = new int[fileSecretLevels.size()];
        for (int i = 0; i < fileSecretLevels.size(); i++) {
            int val = Integer.parseInt(fileSecretLevels.get(i));
            arr[i] = val;
        }
        return arr;
    }
}
